// @ts-ignore
import { Effect, Reducer, Subscription, request } from 'umi';

export interface ArtistModelState {
  artistList: [];
}

export interface ArtistModelType {
  namespace: 'artistModel';
  state: ArtistModelState;
  effects: any;
  reducers: any;
  subscriptions: any;
}

const artistModel: ArtistModelType = {
  namespace: 'artistModel',

  state: {
    artistList: [],
  },

  effects: {
    *getArtistList({ type, payload }: any, { put, call, select }: any) {
      let data = yield request(
        `/artist/list?type=${payload.type.value}&area=${payload.area.value}&initial=${payload.initial.value}&limit=100`,
      );
      yield put({
        type: 'saveArtistList',
        payload: {
          artistList: data.artists,
        },
      });
    },
  },
  reducers: {
    saveArtistList(state: any, action: any) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
  subscriptions: {},
};

export default artistModel;
